package com.millstein.controller;

import com.millstein.request.AddressAddRequest;
import com.millstein.service.AddressService;
import com.millstein.util.JsonData;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电商-公司收发货地址表 前端控制器
 * </p>
 *
 * @author millstein
 * @since 2021-09-08
 */
@RestController
@RequestMapping("/api/address/v1")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping
    @ApiOperation("新增收货地址")
    public JsonData addAddress(@ApiParam("收货地址信息") @RequestBody AddressAddRequest addressAddRequest) {
        addressService.add(addressAddRequest);
        return JsonData.buildSuccess();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询收货地址")
    public JsonData findById(@ApiParam("收货地址id") @PathVariable("id") Long id) {
        return JsonData.buildSuccess(addressService.findById(id));
    }

    @GetMapping("/list")
    @ApiOperation("查询该用户所有的收货地址")
    public JsonData findList() {
        return JsonData.buildSuccess(addressService.findList());
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除收货地址")
    public JsonData delAddress(@ApiParam("收货地址id") @PathVariable("id") Long id) {
        addressService.delete(id);
        return JsonData.buildSuccess();
    }
}

